package com.chennan.pattern.chain.gupao.auth;

import com.chennan.pattern.chain.gupao.general.Handler;

/**
 * @author chennan
 * @create 2022-02
 */
public abstract class AuthHandler<T> {

    protected AuthHandler authHandler;

    public void setAuthHandler(AuthHandler authHandler){
        this.authHandler = authHandler;
    }

    public abstract void handle(String auth);


    public static class Builder<T>{
        private AuthHandler<T> head;
        private AuthHandler<T> tail;

        public Builder<T> addHandle(AuthHandler<T> handler){
            if(this.head == null){
                this.head = this.tail = handler;
            }
            this.tail.setAuthHandler(handler);
            this.tail = handler;
            return this;
        }

        public AuthHandler<T> build(){
            return this.head;
        }

    }
}
